<template>
	<el-container>

		<el-header>
			<div class="left-panel">
				<el-button type="primary" icon="el-icon-plus" @click="add"></el-button>
				<el-button type="info" icon="el-icon-refresh" @click="refresh"></el-button>
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="关键词" clearable></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="list.apiObj" row-key="id"  @selection-change="selectionChange" stripe>
                <!-- <el-table-column type="selection" width="50"></el-table-column> -->
                <el-table-column label="头像昵称" prop="wx_name" width="225"> </el-table-column>
                <el-table-column label="姓名" prop="uname"> </el-table-column>
				<el-table-column label="手机号" prop="phone" align="center"> </el-table-column>
				<el-table-column label="添加时间" prop="create_time" align="center"> </el-table-column>
				<el-table-column label="启用" prop="status" align="center">
						<template #default="scope">
								<el-tag type="success" v-if="scope.row.status == 1">启用</el-tag>
								<el-tag type="error" v-if="scope.row.status == 0">停用</el-tag>
						</template>
				</el-table-column>
				<el-table-column label="操作" fixed="right" align="center" width="285">
					<template #default="scope">
						<el-button-group>
                            <el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
								<template #reference>
									<el-button text type="primary" size="small">删除</el-button>
								</template>
							</el-popconfirm>
                            <el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>

	</el-container>
    <save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></save-dialog>
</template>

<script>
	import saveDialog from './user_save'
    import scSelectFilter from '@/components/scSelectFilter'
	export default {
		name: 'user_group',
		components: {
			saveDialog,
            scSelectFilter
		},
		data() {
			return {
                selection: [],
                dialog: {
					save: false,
					permission: false
				},
				list: {
					apiObj: this.$API.system.deliver.user
				},
				search: {
					keyword: ""
				}
			}
		},
        mounted() {

		},
		methods: {

            //添加
			add(){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.saveDialog.open()
				})
			},
			//编辑
			table_edit(row){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.saveDialog.open('edit').setData(row)
				})
			},
            //删除
			async table_del(row){
				var reqData = {id: row.id}
				var res = await this.$API.system.universal.handle.post(reqData,'/system/deliverUser_del');
				if(res.code == 200){
					this.$refs.table.refresh()
					this.$message.success("删除成功")
				}else{
					this.$alert(res.message, "提示", {type: 'error'})
				}
			},
            //表格选择后回调事件
			selectionChange(selection){
				this.selection = selection;
			},
            //批量删除
			async batch_del(){
				this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？如果删除项中含有子集将会被一并删除`, '提示', {
					type: 'warning'
				}).then(() => {
					var arr = this.selection
					var ob = []
					for(var i=0;i<arr.length;i++){
						  ob.push(arr[i].gid)
					}
					this.table_del({'gid':ob.join(",")})
				}).catch(() => {

				})
			},
			//搜索
			upsearch(){
				this.$refs.table.upData(this.search)
			},
			//标签切换
			tabChange(name){
                this.status = name
                this.$refs.table.reload({'cid':this.cid,'status':this.status})
			},
			filterChange(data){
                this.cid = data.cid
                this.$refs.table.reload({'cid':this.cid,'status':this.status})
				//this.$refs.table.upData(data)
			},
            refresh(){
                this.$refs.table.reload()
            },
            	//本地更新数据
			handleSaveSuccess(data, mode){
				if(mode=='add'){
					this.$refs.table.reload()
				}else if(mode=='edit'){
					this.$refs.table.reload()
				}
			}
		}

	}
</script>

<style>
.pro{
    width:100%;
    float: left;
}
.feng{
    widows:40px;
    height:40px;
    border-radius: 995px;
}
.protitle{
    width: 80%;
    float: left;
    padding-left: 10px;
}
</style>
